package sample.note;

import android.content.ContentValues;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import lombok.SneakyThrows;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class IndexActivity extends AppCompatActivity implements AdapterView.OnItemClickListener{

   String[] names;

   @SneakyThrows
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_index);

      ListView listView = findViewById(R.id.listView);

      ActivityInfo[] actInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES).activities;
      List<String> list = new ArrayList<>();
      for(int i=0; i<actInfo.length; i++){
         ActivityInfo f = actInfo[i];
         list.add(f.name);
      }
      names = list.toArray(new String[list.size()]);

      final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, names);
      listView.setAdapter(adapter);
      listView.setOnItemClickListener(this);

   }

   @SneakyThrows
   @Override
   public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
      String fullPath = names[i];
      Class<?> clazz = Class.forName(fullPath);
      Intent insert = new Intent(getApplicationContext(), clazz);
      startActivity(insert);
   }
}
